//
//  ZLAlert+ZLOther.m
//  ZLAlert-OC
//
//  Created by 科大 on 2024/1/2.
//

#import "ZLAlert+ZLOther.h"

@implementation ZLAlert (ZLOther)

- (ZLAlert *)addLine {
    return [self addLineWithConfig:ZLAlertConfig.shared.lineConfig];
}

- (ZLAlert *)addLineWithConfig:(ZLAlertItemConfig *)config {
    UIView *lastView = self.mainView.subviews.lastObject;
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = config.backgroundColor;
    line.layer.cornerRadius = config.cornerRadius;
    line.layer.borderWidth = config.borderWidth;
    line.layer.borderColor = config.borderColor.CGColor;
    [self.mainView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainView).offset(config.insets.left);
        make.right.equalTo(self.mainView).offset(-config.insets.right);
        if (lastView == nil) {
            make.top.equalTo(self.mainView).offset(config.insets.top);
        } else {
            make.top.equalTo(lastView.mas_bottom).offset(config.insets.top);
        }
        make.height.mas_equalTo(config.height);
    }];
    return [self layoutMainView:10];
}

- (ZLAlert *)addSpace:(CGFloat)height {
    UIView *lastView = self.mainView.subviews.lastObject;
    UIView *space = [[UIView alloc] init];
    space.backgroundColor = [UIColor clearColor];
    [self.mainView addSubview:space];
    [space mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.mainView);
        if (lastView == nil) {
            make.top.equalTo(self.mainView);
        } else {
            make.top.equalTo(lastView.mas_bottom);
        }
        make.height.equalTo(@(height));
    }];
    return [self layoutMainView:0];
}

@end
